<template>
    <div id="OrderSo" v-loading="loading">
        <v-tableTitle :btnConfig="btnConfig"
                      :tableSelectData="tableSelectData"
                      :title="$t('out.osorder')"
                      @del="del"
                      @newCreate="newCreate" @merge="merge" @revocationMerge="revocationMerge"></v-tableTitle>
        <v-table
                :pageSize="pageSize"
                :page="page"
                :tableConfig="tableConfig"
                :tableData="tableData"
                :total="total"
                @findData="getTableData"
                @getTableData="getTableData"
                @searhData="searhData"
                @selectData="selectData"
                @setdialog="setdialog"
                @upData="getTableData"
                ref="table"
        ></v-table>
    </div>
</template>

<script type="text/ecmascript-6">
    import tableTitle from "commons/TableTitle";
    import table from "commons/Table";
    import baseMixin from "@/mixins/BaseMixin";
    import config from "./Config";
    import bus from "../../../../bus/bus"

    export default {
        name: "orderSo",
        mixins: [baseMixin, config],
        data() {
            return {
                loading: false,
                tableConfig: [
                    {
                        label: this.$t('out.externorderkey1'),
                        prop: "externorderkey",
                        input: "input",
                    },
                    {
                        label: this.$t('out.externorderkey3'),
                        prop: "externorderkey3",
                        input: "input",
                    },
                    {
                        label: this.$t('common.status'),
                        prop: "statusdescr",
                        input: "select",
                        options: [
                            {code: '-08', description: this.$t('code.status4')},
                            {code: '08', description: this.$t('code.status5')},
                            {code: '98', description: this.$t('code.status6')}
                        ]
                    },
                    {
                        label: this.$t('config.deliveryAddress'),
                        prop: "c_company",
                        input: "input",
                    },
                    {
                        label: this.$t('out.rtxpaydate'),
                        prop: "rtxpaydate",
                        input: "date",
                    },
                    {
                        label: this.$t('config.num'),
                        prop: "totalqty",
                        input: "input",
                    },
                    {
                        label: this.$t('in.suppliersourcecode'),
                        prop: "rtxfromstorerkey",
                        input: "input",
                    },
                    {
                        label: this.$t('in.rtxpofromhourse1'),
                        prop: "rtxtostorerkey",
                        input: "input",
                    },
                    {
                        label: this.$t('out.tdescription'),
                        prop: "tdescription",
                        input: "input",
                    },
                    {
                        label:  this.$t('app.remark'),
                        prop: "notes",
                        input: "input",
                    },
                    {
                        label: this.$t('out.remeberwho'),
                        prop: "remeberwho",
                        input: "input"
                    },
                    {
                        label: this.$t('out.externalorderkey2'),
                        prop: "externalorderkey2",
                        input: "input",
                    },
                    {
                        label: this.$t('out.area'),
                        prop: "area",
                        input: "select",
                        options: this.getOptions("querycodeLkup/RTXAREA")
                    },
                    {
                        label: this.$t('out.c_state'),
                        prop: "c_state",
                        input: "input",
                    },
                    {
                        label: this.$t('out.c_city1'),
                        prop: "c_city",
                        input: "input",
                    },
                    {
                        label: this.$t('in.receiptfinishflag'),
                        prop: "soorderfinishflag",
                        input: "input",
                        disabled: true
                    },
                    {
                        label: this.$t('in.returnstate'),
                        prop: "somsg",
                        input: "input",
                        disabled: true
                    }
                ],
                tableData: [],
              page: 1,
                pageSize: 10,
                total: 0,
                tableSelectData: [],
                tableSearhData: {},
            };
        },
        computed: {
            btnConfig() {
                return [
                    {label: this.$t('common.create'), certigier: this.newStatus, invalid: "newCreate"},
                    {label: this.$t('common.delete'), certigier: this.deleteStatus, disabled: true, invalid: "del"},
                    {label: this.$t('out.merge'), certigier: this.deleteStatus, disabled: true, invalid: "merge"},
                    {label: this.$t('out.revocationMerge'), certigier: this.deleteStatus, disabled: true, invalid: "revocationMerge"},
                ]
            }
        },
        created() {
        },
        methods: {
            async revocationMerge(data) {
                try {
                    let res = await this.$api.post(`/revokeSoOrders`, data);
                    
                        this.$message.success(res.returnMgr);
                        let page = sessionStorage.getItem('page');
                        this.getTableData(page, this.tableSearhData);
                        
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            async merge(data) {
                try {
                    let res = await this.$api.post(`/mergeSoOrders`, data);
                    
                        this.$message.success(res.returnMgr);
                        let page = sessionStorage.getItem('page');
                        this.getTableData(page, this.tableSearhData);
                        
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            //新建
            async newCreate() {
                try {
                    // let res = await this.$api.get('/codeLookup/nCounter/ORDER');
                  let numberType = 11703;
                  let res = await this.$api.get("/sysNumberRule/getSysNumberByType/"+numberType);
                    
                        this.$store.commit("setRouteId", res.data.data);
                        this.$store.commit("setNewFlag", true);
                        this.$router.push({name: 'orderSoDeawer'});
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            //选中的内容
            selectData(data) {
                this.tableSelectData = data;
            },
            //删除
            async del(data) {
                try {
                    let res = await this.$api.post(`/deleteSoOrders`, data);
                    
                        this.$message.success(res.returnMgr);
                        let page = sessionStorage.getItem('page');
                        this.getTableData(page, this.tableSearhData);
                        
                    
                } catch (e) {
                    this.$message.error(e);
                }
            },
            async getTableData(page, data) {
                try {
                    this.loading = true;
                    let res = await this.$api.post(`/queryOrdersSoList/${page}`, data);
                    
                        this.loading = false;
                        this.tableData = res.page.list;
                      this.page = res.page.curpage;
                        this.pageSize = res.page.pageSize;
                        this.total = res.page.total;
                    
                } catch (e) {
                    this.loading = false;
                    this.$message.error(e);
                }
            },
            //搜索的值
            searhData(data, up) {
                if (!up) {
                    this.tableSearhData = data;
                } else {
                    this.tableSearhData = data;
                    this.getTableData(1, this.tableSearhData);
                }
            },
            //设置弹框
            setdialog(data) {
                this.$store.commit("setRouteData", data);
                this.$router.push({name: 'orderSoDeawer'});
            },
        },
        mounted() {
            ;
            this.$store.commit("setSkip", {});
            this.$store.commit("setRouteId", '');
            this.$store.commit("setNewFlag", false);
            this.$store.commit("setRouteData", {});
            this.$store.commit("setDetailsNew", false);
            this.$store.commit("setTemporary", "");
            this.getTableData(1, {});
        },
        watch: {
            tableSelectData(data) {
                if (this.permissionStatus) {
                    if (data.length > 0) {
                        this.deleteStatus = this.downloadStatus = false;
                        this.allocationStatus = this.fafangStatus = false;
                        this.deliverStatus = this.allPickStatus = this.allShipStatus = false;
                    } else {
                        this.deleteStatus = this.downloadStatus = true;
                        this.allocationStatus = this.fafangStatus = true;
                        this.deliverStatus = this.allPickStatus = this.allShipStatus = true;
                    }
                }
            }
        },
        components: {
            "v-tableTitle": tableTitle,
            "v-table": table,
        }
    };
</script>

<style scoped>
    #OrderSo {
        width: 100%;
        height: 99%;
        padding-top: 6px;
    }
</style>
